package cn.tedu.cinema.member.controller;

import cn.tedu.cinema.base.response.JsonResult;
import cn.tedu.cinema.member.pojo.dto.MemberQuery;
import cn.tedu.cinema.member.service.MemberService;
import cn.tedu.cinema.user.pojo.dto.UserQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

@Slf4j
@RestController
@RequestMapping("/v1/member")
public class MemberController {
    @Autowired
    MemberService memberService;

    @GetMapping("select")
    public JsonResult selectUser(@RequestParam int pageNum,
                                 @RequestParam int pageSize,
                                 @ModelAttribute MemberQuery memberQuery){
        log.debug("查询用户:参数={}",memberQuery);
        return JsonResult.ok(memberService.selectUser(pageNum, pageSize, memberQuery));
    }

    @PostMapping("save")
    public JsonResult saveUser(@RequestParam String userId,
                             @RequestParam String memberLevel){
        log.debug("开通会员:用户ID={}, 会员等级={}", userId, memberLevel);
        // 调用 service 层处理会员开通
        memberService.saveMember(userId, memberLevel);
        return JsonResult.ok();
    }
}
